package router

import (
	"github.com/gin-gonic/gin"
	"shop/controllers"
	"shop/middleware"
	"shop/pkg/logger"
)

var router *gin.Engine

func init() {
	router = gin.Default()
	router.Use(logger.MyLogger())              // 日志
	router.Use(middleware.Cors())              // 处理跨域
	router.Use(middleware.ExceptionMiddleware) // 异常统一处理
	router.POST("/login", controllers.Login)
	router.POST("/register", controllers.Register)

	// v1组添加拦截器，解析token
	v1 := router.Group("/v1", middleware.JWTHandler())
	// user 路由
	user := v1.Group("/user")
	user.GET("/detail", controllers.GetUserMsg)
	user.POST("/cancel", controllers.CanCel)
}

func GetRouter() *gin.Engine {
	return router
}
